<?php
/**
 * Short description for WebCase.php
 *
 * @author    tiglog <xq@tiglog.com>
 * @version   0.1
 * @license   MIT
 * @created   2017-07-27
 */
namespace tiglog\webtest;

use PHPUnit\Framework\TestCase;
use Yii;
use yii\httpclient\Client;

class WebCase extends TestCase
{
    protected $client;
    protected $baseurl;

    public function __construct($name = null, array $data = [], $dataName = '')
    {
        parent::__construct($name, $data, $dataName);
        if ( $this->baseurl ) {
            $baseurl = $this->baseurl;
        } elseif ( defined('TEST_BASEURL') ) {
            $baseurl = TEST_BASEURL;
        } else {
            $baseurl = 'http://127.0.0.1:8000';
        }
        $this->client = new Client(['baseUrl' => rtrim($baseurl, '/')]);
    }

    public function getClient($url=null)
    {
        if ( $url ) {
            $url = ltrim($url, '/');
            return $this->client->createRequest()->setUrl($url);
        } else {
            return $this->client;
        }
    }

    public function __destruct()
    {
        $this->client = null;
    }
}



// vim:ft=php:ts=4:et
